@@ -432,6 +432,7 @@ class UserInfo(BaseModelMixin, LensmanTypeBoolMixin):  | 
            ||
| 432 | 432 | 
                else:  | 
            
| 433 | 433 | 
                             saleclerk_info = {}
               | 
            
| 434 | 434 | 
                         return {
               | 
            
| 435 | 
                + 'has_unionid': bool(self.unionid),  | 
            |
| 435 | 436 | 
                'user_id': self.user_id,  | 
            
| 436 | 437 | 
                'name': self.name,  | 
            
| 437 | 438 | 
                'username': self.username,  | 
            
                @@ -19,7 +19,7 @@ from statistic.models import ConsumeModelSaleStatisticInfo, ConsumeSaleStatistic  | 
            ||
| 19 | 19 | 
                from utils.error.errno_utils import (AdministratorStatusCode, OperatorStatusCode, ProductBrandStatusCode,  | 
            
| 20 | 20 | 
                ProductModelStatusCode, UserStatusCode)  | 
            
| 21 | 21 | 
                from utils.redis.connect import r  | 
            
| 22 | 
                -from utils.redis.rkeys import MEMBER_SEND_COUPON_LIST, MINI_PROGRAM_GIS_LIST  | 
            |
| 22 | 
                +from utils.redis.rkeys import MEMBER_SEND_COUPON_LIST, MINI_PROGRAM_GIS_LIST, MEMBER_UPGRADE_INFO  | 
            |
| 23 | 23 | 
                 | 
            
| 24 | 24 | 
                 | 
            
| 25 | 25 | 
                WECHAT = settings.WECHAT  | 
            
                @@ -407,6 +407,8 @@ def consumer_info_api(request):  | 
            ||
| 407 | 407 | 
                'brand_id': brand.brand_id,  | 
            
| 408 | 408 | 
                'user_id': user_id,  | 
            
| 409 | 409 | 
                })  | 
            
| 410 | 
                + # 会员升级提示  | 
            |
| 411 | 
                + r.set(MEMBER_UPGRADE_INFO % (brand.brand_id, user_id), 1)  | 
            |
| 410 | 412 | 
                user.save()  | 
            
| 411 | 413 | 
                 | 
            
| 412 | 414 | 
                return response(200, 'Submit Consumer Info Success', u'提交消费者信息成功')  | 
            
                @@ -5,6 +5,7 @@ from __future__ import division  | 
            ||
| 5 | 5 | 
                from django.conf import settings  | 
            
| 6 | 6 | 
                from django.db import transaction  | 
            
| 7 | 7 | 
                from django_logit import logit  | 
            
| 8 | 
                +from django_query import get_query_value  | 
            |
| 8 | 9 | 
                from django_response import response  | 
            
| 9 | 10 | 
                from paginator import pagination  | 
            
| 10 | 11 | 
                 | 
            
                @@ -14,6 +15,8 @@ from member.models import (GoodsInfo, GoodsOrderInfo, MemberActivityInfo, Member  | 
            ||
| 14 | 15 | 
                MemberActivitySignupInfo, RightInfo)  | 
            
| 15 | 16 | 
                from utils.error.errno_utils import (MemberActivityStatusCode, MemberGoodStatusCode, MemberRightStatusCode,  | 
            
| 16 | 17 | 
                UserStatusCode)  | 
            
| 18 | 
                +from utils.redis.connect import r  | 
            |
| 19 | 
                +from utils.redis.rkeys import MEMBER_SEND_COUPON_LIST, MEMBER_UPGRADE_INFO  | 
            |
| 17 | 20 | 
                from utils.redis.rshot import get_member_shot_data  | 
            
| 18 | 21 | 
                 | 
            
| 19 | 22 | 
                 | 
            
                @@ -38,6 +41,8 @@ def member(request):  | 
            ||
| 38 | 41 | 
                member_goods = [good.data(user_id) for good in member_goods]  | 
            
| 39 | 42 | 
                member_goods = [good for good in member_goods if not good['has_member_exchange']]  | 
            
| 40 | 43 | 
                 | 
            
| 44 | 
                + upgrade_info, _ = r.getdel(MEMBER_UPGRADE_INFO % (brand_id, user_id))  | 
            |
| 45 | 
                +  | 
            |
| 41 | 46 | 
                     return response(200, data={
               | 
            
| 42 | 47 | 
                'nickname': user.final_nickname,  | 
            
| 43 | 48 | 
                'avatar': user.avatar,  | 
            
                @@ -49,6 +54,7 @@ def member(request):  | 
            ||
| 49 | 54 | 
                'rights': rights,  | 
            
| 50 | 55 | 
                'goods': goods,  | 
            
| 51 | 56 | 
                'member_goods': member_goods,  | 
            
| 57 | 
                + 'has_upgrade': bool(upgrade_info),  | 
            |
| 52 | 58 | 
                })  | 
            
| 53 | 59 | 
                 | 
            
| 54 | 60 | 
                 | 
            
                @@ -162,6 +168,7 @@ def good_exchange(request):  | 
            ||
| 162 | 168 | 
                     brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            
| 163 | 169 | 
                     user_id = request.POST.get('user_id', '')
               | 
            
| 164 | 170 | 
                     good_id = request.POST.get('good_id', '')
               | 
            
| 171 | 
                + good_ids = get_query_value(request, 'good_ids', val_cast_type='listjson')  | 
            |
| 165 | 172 | 
                     name = request.POST.get('name', '')
               | 
            
| 166 | 173 | 
                     phone = request.POST.get('phone', '')
               | 
            
| 167 | 174 | 
                     address = request.POST.get('address', '')
               | 
            
                @@ -172,38 +179,54 @@ def good_exchange(request):  | 
            ||
| 172 | 179 | 
                except UserInfo.DoesNotExist:  | 
            
| 173 | 180 | 
                return response(UserStatusCode.USER_NOT_FOUND)  | 
            
| 174 | 181 | 
                 | 
            
| 175 | 
                - try:  | 
            |
| 176 | 
                - good = GoodsInfo.objects.select_for_update().get(good_id=good_id)  | 
            |
| 177 | 
                - except GoodsInfo.DoesNotExist:  | 
            |
| 178 | 
                - return response(MemberGoodStatusCode.GOOD_NOT_FOUND)  | 
            |
| 182 | 
                + if good_id:  | 
            |
| 183 | 
                + good_ids.append(good_id)  | 
            |
| 179 | 184 | 
                 | 
            
| 180 | 
                - if user.level < good.minlevel:  | 
            |
| 181 | 
                - return response(MemberGoodStatusCode.GOOD_NO_EXCHANGE_PERMISSION)  | 
            |
| 185 | 
                + goods = []  | 
            |
| 182 | 186 | 
                 | 
            
| 183 | 
                - if user.integral < good.integral:  | 
            |
| 184 | 
                - return response(MemberGoodStatusCode.GOOD_INTEGRAL_NOT_ENOUGH)  | 
            |
| 187 | 
                + for good_id in good_ids:  | 
            |
| 188 | 
                + try:  | 
            |
| 189 | 
                + good = GoodsInfo.objects.select_for_update().get(good_id=good_id)  | 
            |
| 190 | 
                + except GoodsInfo.DoesNotExist:  | 
            |
| 191 | 
                + return response(MemberGoodStatusCode.GOOD_NOT_FOUND)  | 
            |
| 185 | 192 | 
                 | 
            
| 186 | 
                - user.integral -= good.integral  | 
            |
| 187 | 
                - user.save()  | 
            |
| 193 | 
                + if user.level < good.minlevel:  | 
            |
| 194 | 
                + return response(MemberGoodStatusCode.GOOD_NO_EXCHANGE_PERMISSION)  | 
            |
| 195 | 
                +  | 
            |
| 196 | 
                + if user.integral < good.integral:  | 
            |
| 197 | 
                + return response(MemberGoodStatusCode.GOOD_INTEGRAL_NOT_ENOUGH)  | 
            |
| 188 | 198 | 
                 | 
            
| 189 | 
                - good.left_num -= 1  | 
            |
| 190 | 
                - good.save()  | 
            |
| 191 | 
                -  | 
            |
| 192 | 
                - GoodsOrderInfo.objects.create(  | 
            |
| 193 | 
                - user_id=user_id,  | 
            |
| 194 | 
                - good_id=good_id,  | 
            |
| 195 | 
                - good_type=good.good_type,  | 
            |
| 196 | 
                - name=name,  | 
            |
| 197 | 
                - phone=phone,  | 
            |
| 198 | 
                - address=address,  | 
            |
| 199 | 
                - )  | 
            |
| 200 | 
                -  | 
            |
| 201 | 
                - if good.good_type == GoodsInfo.PHYSICAL:  | 
            |
| 202 | 
                - # TODO: 通知客服发快递  | 
            |
| 203 | 
                - pass  | 
            |
| 204 | 
                - else:  | 
            |
| 205 | 
                - # TODO: 发放虚拟商品  | 
            |
| 206 | 
                - pass  | 
            |
| 199 | 
                + user.integral -= good.integral  | 
            |
| 200 | 
                + user.save()  | 
            |
| 201 | 
                +  | 
            |
| 202 | 
                + good.left_num -= 1  | 
            |
| 203 | 
                + good.save()  | 
            |
| 204 | 
                +  | 
            |
| 205 | 
                + GoodsOrderInfo.objects.create(  | 
            |
| 206 | 
                + user_id=user_id,  | 
            |
| 207 | 
                + good_id=good_id,  | 
            |
| 208 | 
                + good_type=good.good_type,  | 
            |
| 209 | 
                + name=name,  | 
            |
| 210 | 
                + phone=phone,  | 
            |
| 211 | 
                + address=address,  | 
            |
| 212 | 
                + )  | 
            |
| 213 | 
                +  | 
            |
| 214 | 
                + if good.good_type == GoodsInfo.PHYSICAL:  | 
            |
| 215 | 
                + # TODO: 通知客服发快递  | 
            |
| 216 | 
                + pass  | 
            |
| 217 | 
                + else:  | 
            |
| 218 | 
                + # TODO: 发放虚拟商品  | 
            |
| 219 | 
                + if good.coupon_id:  | 
            |
| 220 | 
                + # 发放券  | 
            |
| 221 | 
                +                r.rpushjson(MEMBER_SEND_COUPON_LIST, {
               | 
            |
| 222 | 
                + 'brand_id': brand_id,  | 
            |
| 223 | 
                + 'user_id': user_id,  | 
            |
| 224 | 
                + 'coupon_id': good.coupon_id,  | 
            |
| 225 | 
                + })  | 
            |
| 226 | 
                + else:  | 
            |
| 227 | 
                + pass  | 
            |
| 228 | 
                +  | 
            |
| 229 | 
                + goods.append(good.data(user_id))  | 
            |
| 207 | 230 | 
                 | 
            
| 208 | 231 | 
                     return response(200, data={
               | 
            
| 209 | 232 | 
                'nickname': user.final_nickname,  | 
            
                @@ -213,7 +236,7 @@ def good_exchange(request):  | 
            ||
| 213 | 236 | 
                'final_integral': user.final_integral,  | 
            
| 214 | 237 | 
                'shots_num': user.shots_num,  | 
            
| 215 | 238 | 
                'level': user.level,  | 
            
| 216 | 
                - 'good': good.data(user_id),  | 
            |
| 239 | 
                + 'goods': goods,  | 
            |
| 217 | 240 | 
                })  | 
            
| 218 | 241 | 
                 | 
            
| 219 | 242 | 
                 | 
            
                @@ -36,46 +36,70 @@ class Command(CompatibilityBaseCommand):  | 
            ||
| 36 | 36 | 
                 | 
            
| 37 | 37 | 
                logger.info(v)  | 
            
| 38 | 38 | 
                 | 
            
| 39 | 
                -                brand_id = v.get('brand_id', 0)
               | 
            |
| 40 | 
                -                user_id = v.get('user_id', 0)
               | 
            |
| 39 | 
                +                brand_id = v.get('brand_id', '')
               | 
            |
| 40 | 
                +                user_id = v.get('user_id', '')
               | 
            |
| 41 | 
                +                coupon_id = v.get('coupon_id', '')
               | 
            |
| 41 | 42 | 
                 | 
            
| 42 | 43 | 
                with transaction.atomic():  | 
            
| 43 | 44 | 
                try:  | 
            
| 44 | 45 | 
                user = UserInfo.objects.get(user_id=user_id)  | 
            
| 45 | 46 | 
                except UserInfo.DoesNotExist:  | 
            
| 46 | 47 | 
                continue  | 
            
| 47 | 
                - rights = RightInfo.objects.filter(is_send_coupon=True, status=True)  | 
            |
| 48 | 
                - for right in rights:  | 
            |
| 49 | 
                - if user.level == UserInfo.MEMBER_LRC:  | 
            |
| 50 | 
                - coupon_id = right.coupon_level1_id  | 
            |
| 51 | 
                - elif user.level == UserInfo.MEMBER_SILVER:  | 
            |
| 52 | 
                - coupon_id = right.coupon_level2_id  | 
            |
| 53 | 
                - elif user.level == UserInfo.MEMBER_SILVER:  | 
            |
| 54 | 
                - coupon_id = right.coupon_level3_id  | 
            |
| 55 | 
                - elif user.level == UserInfo.MEMBER_SILVER:  | 
            |
| 56 | 
                - coupon_id = right.coupon_level4_id  | 
            |
| 57 | 
                - else:  | 
            |
| 58 | 
                - coupon_id = right.coupon_level5_id  | 
            |
| 59 | 
                -  | 
            |
| 48 | 
                + if coupon_id:  | 
            |
| 49 | 
                + # 发放商城兑换券  | 
            |
| 60 | 50 | 
                try:  | 
            
| 61 | 51 | 
                coupon = UserCouponInfo.objects.get(coupon_id=coupon_id)  | 
            
| 62 | 52 | 
                except UserCouponInfo.DoesNotExist:  | 
            
| 63 | 53 | 
                continue  | 
            
| 64 | 54 | 
                 | 
            
| 65 | 
                - for _ in xrange(right.coupon_num):  | 
            |
| 66 | 
                - UserCouponInfo.objects.create(  | 
            |
| 67 | 
                - brand_id=coupon.brand_id,  | 
            |
| 68 | 
                - brand_name=coupon.brand_name,  | 
            |
| 69 | 
                - coupon_id=coupon_id,  | 
            |
| 70 | 
                - user_id=user_id,  | 
            |
| 71 | 
                - coupon_title=coupon.coupon_title,  | 
            |
| 72 | 
                - coupon_detail=coupon.coupon_detail,  | 
            |
| 73 | 
                - coupon_value=coupon.coupon_value,  | 
            |
| 74 | 
                - coupon_image=coupon.coupon_image,  | 
            |
| 75 | 
                - active_at=tc.utc_datetime(),  | 
            |
| 76 | 
                - expire_at=tc.utc_datetime(days=365),  | 
            |
| 77 | 
                - coupon_valid_period=coupon.coupon_valid_period,  | 
            |
| 78 | 
                - coupon_limit_brand_ids=coupon.coupon_limit_brand_ids,  | 
            |
| 79 | 
                - )  | 
            |
| 55 | 
                + UserCouponInfo.objects.create(  | 
            |
| 56 | 
                + brand_id=coupon.brand_id,  | 
            |
| 57 | 
                + brand_name=coupon.brand_name,  | 
            |
| 58 | 
                + coupon_id=coupon_id,  | 
            |
| 59 | 
                + user_id=user_id,  | 
            |
| 60 | 
                + coupon_title=coupon.coupon_title,  | 
            |
| 61 | 
                + coupon_detail=coupon.coupon_detail,  | 
            |
| 62 | 
                + coupon_value=coupon.coupon_value,  | 
            |
| 63 | 
                + coupon_image=coupon.coupon_image,  | 
            |
| 64 | 
                + active_at=tc.utc_datetime(),  | 
            |
| 65 | 
                + expire_at=tc.utc_datetime(days=365),  | 
            |
| 66 | 
                + coupon_valid_period=coupon.coupon_valid_period,  | 
            |
| 67 | 
                + coupon_limit_brand_ids=coupon.coupon_limit_brand_ids,  | 
            |
| 68 | 
                + )  | 
            |
| 69 | 
                + else:  | 
            |
| 70 | 
                + # 发放会员权益  | 
            |
| 71 | 
                + rights = RightInfo.objects.filter(is_send_coupon=True, status=True)  | 
            |
| 72 | 
                + for right in rights:  | 
            |
| 73 | 
                + if user.level == UserInfo.MEMBER_LRC:  | 
            |
| 74 | 
                + coupon_id = right.coupon_level1_id  | 
            |
| 75 | 
                + elif user.level == UserInfo.MEMBER_SILVER:  | 
            |
| 76 | 
                + coupon_id = right.coupon_level2_id  | 
            |
| 77 | 
                + elif user.level == UserInfo.MEMBER_SILVER:  | 
            |
| 78 | 
                + coupon_id = right.coupon_level3_id  | 
            |
| 79 | 
                + elif user.level == UserInfo.MEMBER_SILVER:  | 
            |
| 80 | 
                + coupon_id = right.coupon_level4_id  | 
            |
| 81 | 
                + else:  | 
            |
| 82 | 
                + coupon_id = right.coupon_level5_id  | 
            |
| 83 | 
                +  | 
            |
| 84 | 
                + try:  | 
            |
| 85 | 
                + coupon = UserCouponInfo.objects.get(coupon_id=coupon_id)  | 
            |
| 86 | 
                + except UserCouponInfo.DoesNotExist:  | 
            |
| 87 | 
                + continue  | 
            |
| 88 | 
                +  | 
            |
| 89 | 
                + for _ in xrange(right.coupon_num):  | 
            |
| 90 | 
                + UserCouponInfo.objects.create(  | 
            |
| 91 | 
                + brand_id=coupon.brand_id,  | 
            |
| 92 | 
                + brand_name=coupon.brand_name,  | 
            |
| 93 | 
                + coupon_id=coupon_id,  | 
            |
| 94 | 
                + user_id=user_id,  | 
            |
| 95 | 
                + coupon_title=coupon.coupon_title,  | 
            |
| 96 | 
                + coupon_detail=coupon.coupon_detail,  | 
            |
| 97 | 
                + coupon_value=coupon.coupon_value,  | 
            |
| 98 | 
                + coupon_image=coupon.coupon_image,  | 
            |
| 99 | 
                + active_at=tc.utc_datetime(),  | 
            |
| 100 | 
                + expire_at=tc.utc_datetime(days=365),  | 
            |
| 101 | 
                + coupon_valid_period=coupon.coupon_valid_period,  | 
            |
| 102 | 
                + coupon_limit_brand_ids=coupon.coupon_limit_brand_ids,  | 
            |
| 103 | 
                + )  | 
            |
| 80 | 104 | 
                 | 
            
| 81 | 105 | 
                close_old_connections()  | 
            
                @@ -76,3 +76,4 @@ SUBSCRIBE_USERINFO_LIST = 'subscribe:userinfo:%s'  | 
            ||
| 76 | 76 | 
                 | 
            
| 77 | 77 | 
                MEMBER_SHOT_DATA = 'kodo:member:shot:data'  | 
            
| 78 | 78 | 
                MEMBER_SEND_COUPON_LIST = 'kodo:member:send:coupon:list'  | 
            
| 79 | 
                +MEMBER_UPGRADE_INFO = 'kodo:member:upgrade:info:%s:%s' # brand_id, user_id  |